package com.yzc.mihuyou.controller;


import com.yzc.mihuyou.entity.Attention;
import com.yzc.mihuyou.service.AttentionService;
import com.yzc.mihuyou.service.UserService;
import com.yzc.mihuyou.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 郭权文
 * @since 2022-05-06
 */
@RestController
@RequestMapping("/mihuyou/attention")
public class AttentionController {
    @Autowired
    AttentionService attentionService;
    @Autowired
    UserService userService;

    @PostMapping("/getAttention")
    public JsonResult getAttention(Long id){
        System.out.println(id);
        Map map = new HashMap();
        map.put("data",attentionService.getAttention(id));
        System.out.println( map);

        return  new JsonResult(200,"获取成功", map);
    }

    @PostMapping("/getFans")
    public JsonResult getFans(Long id){
        Map map = new HashMap();
        map.put("data",attentionService.getFans(id));

        return  new JsonResult(200,"获取成功", map);
    }

    @PostMapping("/relation")
    public  JsonResult relation(Long Uid,Long Aid){
        Attention attention = new Attention(Uid,Aid);
        Map map = new HashMap();
        map.put("boolean",attentionService.relation(attention));
        System.out.println(Aid);
        map.put("user",userService.getUser(Aid));
        return  new JsonResult(200,"获取成功", map);
    }

    @PostMapping("/addAttention")
    public JsonResult addAttention(Long Uid,Long Aid){
        Attention attention = new Attention(Uid,Aid);
        return  attentionService.addAttention(attention);
    }

    @PostMapping("/delAttention")
    public JsonResult delAttention(Long Uid,Long Aid){
        Attention attention = new Attention(Uid,Aid);
        return  attentionService.delAttention(attention);
    }

}
